package com.ruoyi.web.controller.message;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.message.domain.MailFromUser;
import com.ruoyi.message.service.IMailFromUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 邮箱发件人账号Controller
 * 
 * @author shushuang
 * @date 2019-10-17
 */
@Controller
@RequestMapping("/message/mail")
public class MailFromUserController extends BaseController
{
    private String prefix = "message/mail";

    @Autowired
    private IMailFromUserService mailFromUserService;

    @RequiresPermissions("message:mail:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/mail";
    }

    /**
     * 查询邮箱发件人账号列表
     */
    @RequiresPermissions("message:mail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MailFromUser mailFromUser)
    {
        startPage();
        mailFromUser.setUserId(ShiroUtils.getUserId());
        List<MailFromUser> list = mailFromUserService.selectMailFromUserList(mailFromUser);
        return getDataTable(list);
    }

    /**
     * 导出邮箱发件人账号列表
     */
    @RequiresPermissions("message:mail:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MailFromUser mailFromUser)
    {
        List<MailFromUser> list = mailFromUserService.selectMailFromUserList(mailFromUser);
        ExcelUtil<MailFromUser> util = new ExcelUtil<MailFromUser>(MailFromUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 新增邮箱发件人账号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存邮箱发件人账号
     */
    @RequiresPermissions("message:mail:add")
    @Log(title = "邮箱发件人账号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MailFromUser mailFromUser)
    {
        mailFromUser.setUserId(ShiroUtils.getUserId());
        return toAjax(mailFromUserService.insertMailFromUser(mailFromUser));
    }

    /**
     * 修改邮箱发件人账号
     */
    @GetMapping("/edit/{uuid}")
    public String edit(@PathVariable("uuid") String uuid, ModelMap mmap)
    {
        MailFromUser mailFromUser = mailFromUserService.selectMailFromUserById(uuid);
        mmap.put("mailFromUser", mailFromUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存邮箱发件人账号
     */
    @RequiresPermissions("message:mail:edit")
    @Log(title = "邮箱发件人账号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MailFromUser mailFromUser)
    {
        return toAjax(mailFromUserService.updateMailFromUser(mailFromUser));
    }

    /**
     * 删除邮箱发件人账号
     */
    @RequiresPermissions("message:mail:remove")
    @Log(title = "邮箱发件人账号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mailFromUserService.deleteMailFromUserByIds(ids));
    }
}
